package com.onion.utils.surface.response;

import com.onion.utils.surface.PageData;
import com.onion.utils.surface.PageVo;

import java.util.List;

public class ResultHelper {

    public static Result success(String message) {
        return Result.instance(0, message);
    }

    public static Result failure(String errmsg){
        return Result.instance(-1, errmsg);
    }

    public static Result failure(int code, String errmsg){
        return Result.instance(code, errmsg);
    }

    public static Result message(int errno, String message){
        return Result.instance(errno, message);
    }

    public static <T> ResultVo<T> failureData(String errmsg){
        ResultVo<T> result = new ResultVo<>();
        result.setCode(-1);
        result.setMessage(errmsg);
        return result;
    }

    public static <T> ResultVo<T> data(T data){
        ResultVo<T> result = new ResultVo<>();
        result.setData(data);
        return result;
    }

    public static <T> ResultVo<T> data(int code, String message, T data){
        ResultVo<T> result = new ResultVo<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static <T> ResultList<T> failureList(String errmsg){
        ResultList<T> result = new ResultList<>();
        result.setCode(-1);
        result.setMessage(errmsg);
        return result;
    }
    public static <T> ResultList<T> list(List<T> listData){
        ResultList<T> result = new ResultList<>();
        result.setData(listData);
        return result;
    }

    public static <T> ResultPage<T> failurePage(String errmsg){
        ResultPage<T> result = new ResultPage<>();
        result.setCode(-1);
        result.setMessage(errmsg);
        return result;
    }
    public static <T> ResultPage<T> page(PageVo pageVo, List<T> listData){
        return page(listData, pageVo.getPageNo(), pageVo.getPageSize(), pageVo.getTotal());
    }

    public static <T> ResultPage<T> page(List<T> listData, int pageNo, int pageSize, int total){
        return page(PageData.instance(listData, pageNo, pageSize, total));
    }

    public static <T> ResultPage<T> page(PageData<T> pageData){
        ResultPage<T> result = new ResultPage<>();
        result.setData(pageData);
        return result;
    }

}
